<?php

namespace core\entity;

/**
 * Phân trang
 *
 * @author BapCai
 */
class Page {

    private $offset = 0;
    private $size = 1;

    public function getOffset() {
        return $this->offset;
    }

    public function getSize() {
        return $this->size;
    }

    public function __construct($offset = 0, $size = 1) {
        if (!is_numeric($offset)) {
            $offset = 0;
        }
        if (!is_numeric($size)) {
            $size = 1;
        }
        $this->offset = $offset;
        $this->size = $size;
    }

    public function offset($offset = 0, $size = 1) {
        if (!is_numeric($offset)) {
            $offset = 0;
        }
        if (!is_numeric($size)) {
            $size = 1;
        }
        $this->offset = $offset;
        $this->size = $size;
    }

    public function pageIndex($index = 1, $size = 1) {
        if (!is_numeric($index) || $index <= 0) {
            $index = 1;
        }
        $index = $index - 1;
        if (!is_numeric($size)) {
            $size = 1;
        }
        $this->offset = $index * $size;
        $this->size = $size;
    }

    public function __toString() {
        $limit = ' ';
        if ($this->offset > 0) {
            $limit .= $this->offset . ', ';
        }
        if ($this->size > 0) {
            $limit .= $this->size;
        }
        return $limit;
    }

}
